package com.woniuxy.oldmanapi.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.oldmanapi.entity.Discharge;
import com.woniuxy.oldmanapi.entity.Othercost;
import com.woniuxy.oldmanapi.service.CategoryTypeService;
import com.woniuxy.oldmanapi.service.DischargeService;
import com.woniuxy.oldmanapi.service.OtherCostService;
import com.woniuxy.oldmanapi.vo.ResponseResult;
import com.woniuxy.oldmanapi.zvo.DischargeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DischargeController {
    @Autowired
    DischargeService dischargeService;
    @GetMapping("/discharge/selectDischargeById/{id}")
    public ResponseResult<DischargeVo> selectDischargeById(@PathVariable(value = "id")int id){
        ResponseResult<DischargeVo> result = new ResponseResult<>();
        try {
            DischargeVo pageInfo = dischargeService.selectDischargeById(id);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }


    //查询咨询者信息
    @GetMapping("/discharge/selectDischarge")
    public ResponseResult<PageInfo<DischargeVo>> selectDischarge(int now, int size, String name){
        ResponseResult<PageInfo<DischargeVo>> result = new ResponseResult<>();
        try {
            PageInfo<DischargeVo> pageInfo = dischargeService.selectDischarge(now, size, name);
            result.setCode(200);
            result.setMsg("查询成功");
            result.setData(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    //更新咨询者信息
    @PostMapping("/discharge/updateDischarge")
    public ResponseResult<Void> updateDischarge(@RequestBody Discharge consulter){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            dischargeService.updateDischarge(consulter);
            result.setCode(200);
            result.setMsg("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    //删除咨询者信息
    @GetMapping("/discharge/deleteDischarge/{id}")
    public ResponseResult<Void> deleteDischarge(@PathVariable(value = "id") int id){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            dischargeService.deleteDischarge(id);
            result.setCode(200);
            result.setMsg("删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
    //结算
    @GetMapping("/discharge/settlementDischarge/{id}")
    public ResponseResult<Void> settlementDischarge(@PathVariable(value = "id") int id){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            dischargeService.settlementDischarge(id);
            result.setCode(200);
            result.setMsg("结算成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }

    //新增咨询者信息
    @PostMapping("/discharge/insertDischarge")
    public ResponseResult<Void> insertConsulter(@RequestBody Discharge consulter){
        ResponseResult<Void> result = new ResponseResult<>();
        try {
            dischargeService.insertDischarge(consulter);
            result.setCode(200);
            result.setMsg("添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            result.setCode(203);
            result.setMsg("系统错误，请联系管理员!!!");
        }
        return result;
    }
}
